package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.response.StoreResponse;
import com.baihan.angus.app.game.common.util.ImageLoader;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

public class StoreListAdp extends BaseAdp<StoreResponse.DataX.Data, StoreListAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_store_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        StoreResponse.DataX.Data data = getItem(position);

        vh.tvStoreName.setText(data.getName());
        vh.tvStorePhone.setText("联系电话：" + data.getMobile());
        vh.tvStoreAddr.setText(data.getAddress());

        ImageLoader.loadImage(BaseApplication.getApplication().getApplicationContext(),
                vh.ivStore, data.getAvatar(), R.mipmap.ic_test_bg, 4);

        vh.llItem.setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        QMUIRadiusImageView ivStore;
        TextView tvStoreName, tvStorePhone, tvStoreAddr;
        LinearLayout llItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivStore = itemView.findViewById(R.id.ivStore);
            tvStoreName = itemView.findViewById(R.id.tvStoreName);
            tvStorePhone = itemView.findViewById(R.id.tvStorePhone);
            tvStoreAddr = itemView.findViewById(R.id.tvStoreAddr);
            llItem = itemView.findViewById(R.id.llItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
